#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

class Solution
{
public:
    static int minNumberOfFrogs(string croakOfFrogs)
    {
        int n = croakOfFrogs.size();
        string s = "croak";
        int hash[5];
        unordered_map<char, int> index;
        for(int i=0; i<s.size(); i++)
        {
            index[s[i]] = i;
        }

        for(int i=0; i<n; i++)
        {
            char ch = croakOfFrogs[i];
            if(ch == 'c')
            {
                if(hash[4])
                    hash[4]--;
                hash[0]++;
            }
            else
            {
                int j = index[ch];
                if(hash[j-1] == 0)
                    return -1;
                hash[j-1]--;
                hash[j]++;
            }
        }

        for(int i=0; i<5-1; i++)
        {
            if(hash[i] != 0)
                return -1;
        }
        return hash[4];
    }
};